home *** CD-ROM | disk | FTP | other *** search
- /*
- file: post-send
- by: A.C. van der Ham
- e-mail: a.c.vanderham@et.tudelft.nl
-
- purpose: to be used together with digester to enable easy reply to messages
- warning: only works with UNIX servers for now
- where: compile it and put it in your html scripts directory
- notice: don't forget to set the correct path for the info-mac files
- */
-
- #define PATH "/home/vdham/Mosaic/info-mac/"
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
-
- #define MAXLINE 512
- #define OK 0
- #define ERROR 1
- #define ITEMTEXT "<a name=item%d"
- #define INFOMAC "info-mac@sumex-aim.stanford.edu"
- #define EOM "<a name=item"
-
- int IsEmailChar( char c )
- {
- if( (c>='a') && (c<='z') ) return(1);
- if( (c>='A') && (c<='Z') ) return(1);
- if( (c>='0') && (c<='9') ) return(1);
- if(c=='.') return(1);
- if(c=='_') return(1);
- if(c=='-') return(1);
- if(c=='%') return(1);
- return(0);
- }
-
- int findmessage( int item, char *file )
- {
- FILE *inP;
- char line[256], searchString[100], address[80], *cptr, *begin;
-
- strcpy( line, PATH );
- strcat( line, file );
-
- searchString[0]=0;
-
-
- sprintf( searchString, ITEMTEXT, item );
-
- strcpy( address, INFOMAC );
-
- if( (inP = fopen( line, "r" )) != NULL )
- {
- do {
- fgets( line, 256, inP );
- } while( (!feof(inP)) &&
- (strstr(line, searchString)==NULL) );
-
- if( feof(inP) )
- return(ERROR);
-
- fputs( "<pre>", stdout );
-
- do {
- fgets( line, 256, inP );
-
- /* print lines that do not contain code */
- if( (strstr(line,"<")==NULL) && (strstr(line,">")==NULL) )
- fputs( line, stdout );
-
-
- /* check for the From string */
- if( (cptr=strstr( line, "From: " ))!=NULL )
- {
- cptr += 6;
- strcpy(address, cptr);
-
- /* terminate the address string */
-
- if( (cptr=strstr(address,"\n")) != NULL)
- *cptr=0;
-
- /* look for delimiters < and >
- if( (cptr=strstr(address,"<")) != NULL)
- {
- strcpy(address, cptr+4);
- if( (cptr=strstr(address,">")) != NULL)
- *cptr=0;
- }
- */
-
- /* find any spaces an terminate from there
- if( (cptr=strstr(address," ")) != NULL)
- *cptr=0;
- */
-
- strcpy(searchString, address);
-
- /* more intelligent e-mail parser */
- if( (cptr=strstr(searchString,"@"))!=NULL)
- {
- /* find beginning */
- begin=cptr; begin--;
- while(IsEmailChar(*begin) && begin>=searchString) begin--;
-
- /* find ending */
- begin++; cptr++;
- while(IsEmailChar(*cptr) && *cptr!=0 ) cptr++;
-
- /* terminate address and copy */
- *cptr=0;
- strcpy(address, begin);
- }
- else
- strcpy(address, INFOMAC);
- }
- } while( (!feof(inP)) &&
- (strstr(line, EOM)==NULL) );
-
- fputs( "</pre>", stdout );
-
- fprintf( stdout, "Reply to: <a href=mailto:%s>%s</a><p>\n", address, address );
- fprintf( stdout, "Reply to: <a href=mailto:%s>%s</a><p>\n", INFOMAC, INFOMAC );
-
- fclose(inP);
- }
- else
- {
- return(ERROR);
- }
- return(OK);
- }
-
-
- int main( int argc, char *argv[] )
- {
- char *cptr;
- char file[80];
- int item=0;
-
- argc=argc;
-
- fprintf(stdout, "Content-type: text/html\n\n");
-
- if( argv[1]!=NULL)
- {
- if((cptr=strstr(argv[1],","))!=NULL)
- {
- *cptr=0;
- item=atoi(argv[1]);
- strcpy(file, cptr+1);
- if( findmessage( item, file ) == ERROR)
- {
- fprintf(stdout, "<title>can't find message</title>\n");
- fprintf(stdout, "Sorry, something went wrong in message selection.<p>\n");
- fprintf(stdout, "Please notify: <a href=mailto:a.c.vanderham@et.tudelft.nl>André van der Ham</a>.<p>\n");
- fprintf(stdout, "ERROR: can't find message?!\n");
- }
- }
- else
- {
- fprintf(stdout, "<title>no delimiter</title>\n");
- fprintf(stdout, "Sorry, something went wrong in message selection.<p>\n");
- fprintf(stdout, "Please notify: <a href=mailto:a.c.vanderham@et.tudelft.nl>André van der Ham</a>.<p>\n");
- fprintf(stdout, "ERROR: File name delimiter not found?!\n");
- }
- }
- else
- {
- fprintf(stdout, "<title>no arguments</title>\n");
- fprintf(stdout, "Sorry, something went wrong in message selection.<p>\n");
- fprintf(stdout, "Please notify: <a href=mailto:a.c.vanderham@et.tudelft.nl>André van der Ham</a>.<p>\n");
- fprintf(stdout, "ERROR: Can't find any arguments to query?!\n");
- }
-
- return(0);
- }
-